from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time
from selenium.webdriver import ActionChains


driver = webdriver.Chrome()
driver.maximize_window()
driver.get("https://www.baidu.com")
time.sleep(2)

# 鼠标悬停到设置
ActionChains(driver).move_to_element(driver.find_element(By.XPATH, "//span[text()='设置']")).perform()
time.sleep(1)
# 点击-搜索设置
driver.find_element(By.XPATH, "//span[text()='搜索设置']").click()
time.sleep(1)
# 点击-保存设置
driver.find_element(By.XPATH, "//a[text()='保存设置']").click()
time.sleep(1)

# # 获取弹出框信息
# print(driver.switch_to.alert.text)
# # 确定弹出框信息
# driver.switch_to.alert.accept()
# # 关闭警告
# driver.switch_to.alert.dismiss()
time.sleep(5)
driver.quit()
